import { SUPPLIER_TYPE_SELECT_LIST, SUPPLIER_CATEGORY_SELECT_LIST } from '@/pages/supplier/constants/common'
import { getInitialFieldsValue, list2Obj } from '@/pages/supplier/utils'
import { convertSupplierReasons } from '@/pages/supplier/constants'
const {
  ELIMINATION_REASONS_MAP_OBJECT,
} = convertSupplierReasons
// 供应商管理 - 淘汰供应商

const FORM_ITEM_LIST = [
  { prop: 'supplierCode', label: '供应商代码', type: 'input', },
  { prop: 'supplierName', label: '供应商名称', type: 'input', },
  { prop: 'supplierClassify', label: '供应商分类', type: 'select', clearable: true, options: SUPPLIER_CATEGORY_SELECT_LIST },
  { prop: 'supplierType', label: '供应商类型', type: 'select', clearable: true, options: SUPPLIER_TYPE_SELECT_LIST },
  { prop: 'mainCategoryId', label: '主营品类', type: 'categorySelect', },
  { prop: 'reason', label: '淘汰原因', type: 'input', },
  { prop: 'createUser', label: '提交人', type: 'input', },
  { prop: 'createDate', label: '淘汰日期', type: 'datePicker', valueFormat: 'yyyy-MM-dd' },
]
const INITIAL_FIELDS_VALUE = getInitialFieldsValue(FORM_ITEM_LIST)

const initTableColumns = (parent) => {
  return [
    { title: '供应商代码', key: 'supplierCode', },
    {
      title: '供应商名称',
      key: 'supplierName',
      render: (h, { row }) => {
        return <a onClick={ () => { parent.handleViewSupplierDetail(row) }}>{row.supplierName}</a>
      }
    },
    { title: '供应商分类',
      key: 'supplierClassify',
      formatter (row, column, cellValue, index) {
        return list2Obj(SUPPLIER_CATEGORY_SELECT_LIST)[cellValue]
      }
    },
    { title: '供应商类型',
      key: 'supplierType',
      formatter (row, column, cellValue, index) {
        return list2Obj(SUPPLIER_TYPE_SELECT_LIST)[cellValue]
      }
    },
    { title: '主营品类代码', key: 'mainCategoryCode', },
    { title: '主营品类', key: 'mainCategory', },
    { title: '提交人', key: 'createUser', },
    { title: '淘汰日期', key: 'createTime', },
    { title: '淘汰原因',
      key: 'reason',
      formatter (row, column, cellValue, index) {
        return ELIMINATION_REASONS_MAP_OBJECT[cellValue]
      }
    },
  ]
}

export {
  INITIAL_FIELDS_VALUE,
  FORM_ITEM_LIST,
  initTableColumns
}
